#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
using namespace std;


//string Convert_to_lowercase(string s)
//{
//    string news;
//    for (int i = 0; i < s.size(); i++)
//    {
//        if ((s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z'))
//        {
//            if (s[i] >= 'A' && s[i] <= 'Z')
//            {
//                s[i] = s[i] + 32;
//            }
//            news += s[i];
//        }
//    }
//    return news;
//}
//bool isPalindrome(string s) {
//    string news = Convert_to_lowercase(s);
//    int left = 0;
//    int right = news.length() - 1;
//    while (left < right)
//    {
//        cout<<left<<endl;
//        left++;
//        right++;
//    }
//    return true;
//}
//int main()
//{
//    string s1 = "A man, a plan, a canal: Panama";
//    bool a=isPalindrome(s1);
//    cout << a << endl;
//	return 0;
//}


//void func()
//{
//    static int i = 10;
//    i--;
//    cout << &(i) << endl;
//}
//void func2()
//{
//    cout <<endl;
//}



string reverseStr(string s, int k) {
    int left = 0;
    int right = 0;

    int count_l = 0;
    int count_r = 0;

    int count = 0;
    for (int i = 0; i < s.length(); i++)
    {
        if (((count_r - count_l + 1) == 2 * k)
            || ((s.length() - count_r + 1) < k)
            || (((s.length() - count_r + 1) >= k) && ((s.length() - count_r + 1) < 2 * k)))
        {
            left = count_l;
            right = count_r;
            while (left < right)
            {
                swap(s[left], s[right]);
                left++;
                right--;
            }
            count_l = count_r + 1;
        }
        count_r++;
    }
    return s;
}
int main()
{
    string s = "abcd";
    
    cout <<reverseStr(s, 2)<< endl;
    return 0;
}